<?php
/*
Plugin Name: Technorati Buzz Panel
Plugin URL: http://dreamscapecms.com/
Description: The latest buzz about your site from Technorati
Dashboard: 1.0b3
Version: 0.1
Author: Ryan Miglavs (but don't blame me)
Author URL: http://dreamscapecms.com/
*/

class BuzzPanel extends DashboardPanel {
	var $name = 'Buzz Summary';
	
	function BuzzPanel() {
		include('../../funcs/rss.class.php');
		$rss = new easyRSS;
		$totals = $auth->getTotals();
		$summary_header = sprintf(L_OVER_TOTAL_USAGE, $totals['user_count'], $totals['total_count']);
		$summary_body = $auth->createSummary();
		$buzz_header = sprintf(L_LATEST_BUZZ, YOUR_SITE, getOption('sitename'));
		$technorati_url = 'http://feeds.technorati.com/cosmos/rss/?url='.YOUR_SITE;
		if(!isset($_SESSION['remote_buzz'])){
			$sitebuzz = getRemoteFile($technorati_url);
			$buzz = $_SESSION['remote_buzz'] = $rss->parse($sitebuzz->results);
		} else {
			$buzz = $_SESSION['remote_buzz'];
		}
		$has_buzz = (count($buzz['items']) > 1 && !empty($buzz['items'][0]['link']));
		$no_buzz = sprintf(L_NO_BUZZ, COMPANY_URL, CMS_NAME);
		
		$this->html = "
		<div id='summary'>
		  <h1>$summary_header</h1>
		    $summary_body
		  <div id='theBuzz'>
		    <h1>$buzz_header</h1>";

		if(!empty($buzz['items'])){
			foreach($buzz['items'] as $ind => $val){ 
				if($ind < 9){
					$title = $val['title'];
					$descr = (strlen($val['description']) > 330) ? substr($val['description'], 0, 330)."&hellip;" : $val['description'];
					$link = $val['link'];
					if(!$has_buzz){
						$this->html .= "<h2>$no_buzz</h2>";
						break;
					}
				}
				$this->html .= "<h2><a class='buzz' href='$link' target='_blank' title='".strip_tags($descr)."'>$title</a></h2>";
			}
		} else {
			$this->html .= "<h2>$no_buzz</h2>";
		}

		$this->html .="
		  </div>
		</div>";
	}
}

$buzz_panel = new DashboardPanel;
?>